<template>
    <el-container>
        <el-header>
            <div style="text-align:right;height: 60px;line-height: 60px;">
                <img :src="this.$baseUrl + user.headImage" style="width: 50px;
                        height: 50px;
                        border-radius: 50%;" /> <span style="font-weight:600;">{{ user.name }}</span>
                <span @click="eventLogout">退出登录</span>
            </div>
        </el-header>
        <el-container>
            <el-aside width="200px">
                <!-- <el-menu :router="true" default-active="2" class="el-menu-vertical-demo" @open="handleOpen"
                    @close="handleClose">
                    <el-submenu index="1">
                        <template slot="title">
                            <i class="el-icon-location"></i>
                            <span>商品管理</span>
                        </template>
                        <el-menu-item :index="{ name: 'product/category', params: { name: '分类管理' } }">
                            <i class="el-icon-document"></i>
                            <span slot="title">分类管理</span>
                        </el-menu-item>
                        <el-menu-item :index="{ name: 'product/brand', params: { name: '品牌管理' } }">
                            <i class="el-icon-document"></i>
                            <span slot="title">品牌管理</span>
                        </el-menu-item>
                        <el-menu-item :index="{ name: 'product/add', params: { name: '添加商品' } }">
                            <i class="el-icon-document"></i>
                            <span slot="title">添加商品</span>
                        </el-menu-item>
                    </el-submenu>
                    <el-menu-item :index="{ name: 'system/user', params: { name: '系统用户' } }">
                        <i class="el-icon-menu"></i>
                        <span slot="title">系统用户</span>
                    </el-menu-item>

                    <el-menu-item :index="{ name: 'order/list', params: { name: '订单列表' } }">
                        <i class="el-icon-setting"></i>
                        <span slot="title">订单列表</span>
                    </el-menu-item>
                </el-menu> -->
            </el-aside>
            <el-main>
                <router-view />
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
export default {
    data() {
        return {
            url: this.$baseUrl,
            user: {
                headImage: ''
            }
        }
    },
    mounted() {
        //在页面初始化的时候，获取缓存，
        let u = localStorage.getItem('ph4_login_info')
        if (u == null) {
            this.$router.push('/login')
        }
        //我们存进去的时候，是将json对象转换为字符串，那么拿出来之后，也可以将这个字符串转换json对象
        this.user = JSON.parse(u)
    },
    methods: {
        //退出登录事件
        eventLogout() {
            //需要删除缓存
            localStorage.removeItem('ph4_login_info')

            this.$router.push('/login')
        },
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        }
    }

}
</script>

<style>
.el-header,
.el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
}

.el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
}

.el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
}

body>.el-container {
    margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
    line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
    line-height: 320px;
}
</style>